package com.dhcc.bpm.alarm.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dhcc.bpm.alarm.entity.AlarmObjectGroup;
import com.dhcc.bpm.alarm.mapper.AlarmObjectGroupMapper;
import com.dhcc.bpm.alarm.service.IAlarmObjectGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class AlarmObjectGroupServiceImpl extends ServiceImpl<AlarmObjectGroupMapper, AlarmObjectGroup> implements IAlarmObjectGroupService {

	@Autowired
	AlarmObjectGroupMapper alarmObjectGroupMapper;
	

	/** 根据对象表ID删除关系表数据 **/
	@Override
	public boolean removeByObjectIds(List<Long> objIds, Long groupId) {
		
		if (objIds.isEmpty()) {
        	log.error("没有可删除的数据！");
        	return false;
        }
		
		QueryWrapper<AlarmObjectGroup> deleteWrapper = new QueryWrapper<>();
		deleteWrapper.eq("GROUP_ID", groupId);
		deleteWrapper.in("OBJECT_ID", objIds);
	    int delNum = alarmObjectGroupMapper.delete(deleteWrapper);
	    
	    if(delNum > 0) {
	    	return true;
	    }
	    
	    return false;
	    
	}
	
	/** 根据群组表ID删除关系表数据 **/
	@Override
	public boolean removeByGroupId(Long groupId) {
		if (null == groupId) {
        	log.error("没有可删除的数据！");
        	return false;
        }
		
		QueryWrapper<AlarmObjectGroup> deleteWrapper = new QueryWrapper<>();
	    deleteWrapper.eq("GROUP_ID", groupId);
	    alarmObjectGroupMapper.delete(deleteWrapper);
	    
	    return true;
		
	}
	
	/**
	 * 根据多个分组id删除关联关系。
	 */
	@Override
	public boolean removeByGroupIds(List<Long> groupIds) {
		if (null == groupIds) {
        	log.error("没有可删除的数据！");
        	return false;
        }
		
		QueryWrapper<AlarmObjectGroup> deleteWrapper = new QueryWrapper<>();
	    deleteWrapper.in("GROUP_ID", groupIds);
	    int delNum = alarmObjectGroupMapper.delete(deleteWrapper);
	    
	    if(delNum > 0) {
	    	return true;
	    }
	    
	    return false;
	}

}
